<template>
	<view v-if="cart.length !== 0">
		<!-- 收货地址 -->
		<my-address></my-address>
		
		<!-- 购物车标题 -->
		<view class="title">
			<uni-icons type="shop" size="22"></uni-icons>
			<view class="title-text">购物车</view>
		</view>

		<!-- 购物车列表 -->
		<view class="cart-list">
			<uni-swipe-action>
				<block v-for="(item,index) in cart" :key="index">
					<uni-swipe-action-item :right-options="options" @click="delItem(item)">
						<my-goods :goods="item" :show-radio="true" :show-num="true" @radio-change="radioChange"
							@num-change="numChangeHandler"></my-goods>
					</uni-swipe-action-item>
				</block>
			</uni-swipe-action>
		</view>
		
		<!-- 结算 -->
		<my-settle></my-settle>
		
	</view>
	
	<view v-else>
		购物车为空
	</view>
</template>

<script>
	import badgeMixins from '@/mixins/tabbar-badge.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'

	export default {
		mixins: [badgeMixins],
		data() {
			return {
				options:[
					{
						text:'删除',
						style:{
							backgroundColor:'#c00000'
						}
					}
				]
			};
		},
		computed: {
			...mapState('moduleCart', ['cart'])
		},
		methods: {
			...mapMutations('moduleCart', ['updateRadioChange', 'updateNumCount','deleteGoodItem']),
			radioChange(val) {
				this.updateRadioChange(val)
			},
			numChangeHandler(val) {
				this.updateNumCount(val)
			},
			delItem(goods){
				this.deleteGoodItem(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.title {
		display: flex;

		.title-text {
			margin-left: 10rpx;
		}
	}
</style>
